package com.api.regression.group.createzlink.folder;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.AssertApi;
import com.api.test.UrnType;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.UrlServiceResultApi;

@ContextConfiguration(locations = { "classpath:/group/group-context.xml" })
public class CreateGroupFolderZlink extends AbstractApiTest {

	@Value("#{editgroupdocuments['user.notEditor'].appId}")
	private String participantId;

	@Value("#{editgroupdocuments['user.notEditor'].password}")
	private String participantPassword;

	@Value("#{editgroupdocuments['group.toCreate'].urn}")
	private String groupUrn;

	@Value("#{editgroupdocuments['group.toCreate'].folderUrn}")
	private String groupFolderUrn;

	@BeforeClass
	public void setUpVariables() {

		getApi().login(participantId, participantPassword);
	}

	@Test
	public synchronized void testGenerateZlink() throws ZyncroApiException {

		String expiration = null;
		String password = null;

		UrlServiceResultApi result = getApi().getService(IGroupApiService.class).createDocumentZlink(groupUrn, groupFolderUrn, expiration,
				password);

		AssertApi.assertUrnType(result.getUrl(), UrnType.ZLINK);
	}

	@Test
	public synchronized void testGenerateZlinkExpiration() throws ZyncroApiException {

		String expiration = "1343407414295";
		String password = null;

		UrlServiceResultApi result = getApi().getService(IGroupApiService.class).createDocumentZlink(groupUrn, groupFolderUrn, expiration,
				password);

		AssertApi.assertUrnType(result.getUrl(), UrnType.ZLINK);
	}

	@Test
	public synchronized void testGenerateZlinkPassword() throws ZyncroApiException {

		String expiration = null;
		String password = "123456";

		UrlServiceResultApi result = getApi().getService(IGroupApiService.class).createDocumentZlink(groupUrn, groupFolderUrn, expiration,
				password);

		AssertApi.assertUrnType(result.getUrl(), UrnType.ZLINK);
	}
}
